package com.csf.common.protobuff.serialiser;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;

public class ProtoBuffSerialiser extends OneToOneEncoder{

	private static final byte[] LENGTH_PLACEHOLDER = new byte[4];
	// check if estimated length required

	@Override
	protected Object encode(ChannelHandlerContext ctx, Channel channel,
			Object message) throws Exception {
		// convert to byte array - TODO - format big indian ?
		byte bytes[] =  (byte[]) message;
		int dataLength = bytes.length;
		ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
		buf.writeInt(dataLength);
		buf.writeBytes(bytes);
		return buf;

	}

}
